#!/usr/bin/env bash
set -e

# S2I assemble script for extending the strimzi/kafka-connect image with additional Kafka Connect plugins
# This script is responsible for assembling distributed Kafka Connect worker with custom plugins directory

if [ "$1" = "-h" ]
then
  ./usage
  exit 0
fi

export S2I_SOURCE_DIR=/tmp/src
export TARGET_DIR=/tmp/kafka-plugins

echo "Assembling plugins into custom plugin directory $TARGET_DIR"

mkdir -p "$TARGET_DIR"

if [ -d "$S2I_SOURCE_DIR" ] && [ "$(ls -A "$S2I_SOURCE_DIR")" ]; then
  echo "Moving plugins to $TARGET_DIR"
  mv "$S2I_SOURCE_DIR"/* "$TARGET_DIR"
fi
